myApp.onPageInit('application-status-list', function (page) {
    console.log("onPageInit " + page.name);

    var uuids = [];
    var list = $$(page.container).find('.list-block'),
        empty = $$(page.container).find('.empty-view'),
        refreshContainer = $$(page.container).find('.pull-to-refresh-content');
    list.data('request', null);
    list.data('lastpage', false);
    list.data('nextpage', 0);

    $$(document).once('pageBeforeRemove', '.page[data-page="application-status-list"]', function () {
        console.log('pageBeforeRemove ' + page.name)
        $$.each(uuids, function (index, uid) {
            delete myApp.template7Data[uid];
        });
    });

    function loadPage() {
        var refresing = list.data('nextpage') == 0,
            req = true;
        $$.getJSONP(SERVER_PATH + 'getApplicationStatusList.do', {num: PAGE_SIZE, start: (list.data('nextpage') * PAGE_SIZE)}, function (json) {
            if (json.code == 1) {
                list.data('nextpage', list.data('nextpage') + 1);

                if (refresing) {
                    list.find('ul').children().remove();
                }

                $$.each(json.results, function (index, value) {
                    if (value.isLastPage) {
                        list.data('lastpage', true);
                    }

                    preprocessData('applicationStatusList', value);
                    uuids.push(value.uuid);
                    var html = Template7.templates.applyStatusTemplate(value);
                    list.find('ul').append(html);
                });
                empty[list.find('ul').children().length > 0 ? 'hide' : 'show']();
            }

            list.data('request', null);
            if (refresing) {
                myApp.pullToRefreshDone();
            }
        });
        list.data('request', req);
    }

    $$(page.container).find('.infinite-scroll').on('infinite', function () {
        if (list.data('lastpage') || list.data('request')) {
            return;
        }

        loadPage();
    });
    refreshContainer.on('refresh', function () {
        var request = list.data('request');
        if (request) {
            request.abort();
        }
        list.data('request', null);
        list.data('lastpage', false);
        list.data('nextpage', 0);
        loadPage();
    });
    myApp.pullToRefreshTrigger(refreshContainer);
});


myApp.onPageBeforeInit('application-status-detail', function (page) {
    if (myApp.padApp) {
        $$(page.navbarInnerContainer).find('.left').css('visibility', 'hidden');
    }
});
myApp.onPageInit('application-status-detail', function (page) {
    console.log("onPageInit " + page.name);

    var params = page.query,
        data = myApp.template7Data[params.uuid],
        confirmList = data.confirmList, index = 0,
        ul = $$(page.container).find('.list-block ul');

    var html = Template7.templates.applyStatusTemplate(data);
    var header = $$(html);
    header.find('.item-after').remove();
    header.find('a.item-link').attr('href', '#').css('background', ul.css('background'));
    ul.append(header);

    ul.append('<li class="list-group-title">详细申请流程</li>');
    var lastOne = $$('<li class="item-content item-timedot item-timedot-last">' +
        '<div class="item-media"><span></span></div>' +
        '<div class="item-inner">' +
        '<div class="item-subtitle">查看更多</div>' +
        '</div>' +
        '</li>');


    $$.each(confirmList, function (index, value) {
        value.index = confirmList.length - index;
    });
    function loadPage() {
        lastOne.remove();
        for (var i = 0; i < 4 && index < confirmList.length; i++) {
            var html = Template7.templates.applyConfirmTemplate(confirmList[index++]);
            ul.append(html);
        }
        if (index < confirmList.length) {
            ul.append(lastOne);
        }
    }
    lastOne.click(loadPage).click();

});